home *** CD-ROM | disk | FTP | other *** search
/ Ultra Gameplayers 101 / Ultra Game Players Magazine, No. 101 - September 1997 (Imagine Publishing, Inc.)(1997).iso / pc / new_ugp.dxr / 00311_databaseClass.ls < prev    next >
Encoding:
Text File  |  1997-07-10  |  3.4 KB  |  130 lines

  1. property sectiontree
  2.  
  3. on new me, textsource
  4.   put "Loading database..."
  5.   set sectiontree to [:]
  6.   if listp(textsource) then
  7.     repeat with source in textsource
  8.       load(me, source)
  9.     end repeat
  10.   else
  11.     load(me, textsource)
  12.   end if
  13.   return me
  14. end
  15.  
  16. on load me, textsource
  17.   set datadelimiter to "|"
  18.   set mytext to the text of field textsource
  19.   set startTime to the ticks
  20.   set proptext to line 1 of mytext
  21.   set propflatlist to texttolist(proptext, datadelimiter)
  22.   set template to symbol(propflatlist)
  23.   delete line 1 of mytext
  24.   repeat with index = 1 to the number of lines in mytext
  25.     set curline to line index of mytext
  26.     set rec to filltemplate(template, curline, datadelimiter)
  27.     if stringp(rec) then
  28.       alert(rec & ";Error was in line " & index & ".")
  29.       halt()
  30.     end if
  31.     set section to symbol(the section of rec)
  32.     set category to symbol(the category of rec)
  33.     set sectionlist to getaProp(sectiontree, section)
  34.     if voidp(sectionlist) then
  35.       addProp(sectiontree, section, [:])
  36.       set sectionlist to getProp(sectiontree, section)
  37.     end if
  38.     set catlist to getaProp(sectionlist, category)
  39.     if voidp(catlist) then
  40.       addProp(sectionlist, category, [])
  41.       set catlist to getProp(sectionlist, category)
  42.     end if
  43.     append(catlist, rec)
  44.   end repeat
  45.   set endTime to the ticks
  46.   put "interpret:" && endTime - startTime
  47. end
  48.  
  49. on loadfiles me
  50.   if isMac() then
  51.     set basepath to the pathName
  52.     delpush(":")
  53.     set basepath to item 1 to the number of items in basepath - 2 of basepath
  54.     delpop()
  55.     set imagepath to basepath & ":images:"
  56.     set videopath to basepath & ":movies:"
  57.     set textpath to basepath & ":text:"
  58.   else
  59.     set imagepath to "..\images\"
  60.     set videopath to "..\movies\"
  61.     set textpath to "..\text\"
  62.   end if
  63.   set data to []
  64.   set imageptr to 140
  65.   set movieptr to 200
  66.   repeat with index = 1 to count(data)
  67.     set rec to getAt(data, index)
  68.     if not voidp(getaProp(rec, #image)) then
  69.       set image to getaProp(rec, #image)
  70.       if image <> EMPTY then
  71.         set imageloc to image
  72.         set pos to offset("\", imageloc)
  73.         repeat while pos > 0
  74.           put ":" into char pos of imageloc
  75.           set pos to offset("\", imageloc)
  76.         end repeat
  77.         put imageloc
  78.         importFileInto(member imageptr, imageloc)
  79.         set imageptr to imageptr + 1
  80.       else
  81.         set imageloc to EMPTY
  82.       end if
  83.     end if
  84.     if not voidp(getaProp(rec, #movie)) then
  85.       set video to getaProp(rec, #movie)
  86.       if video <> EMPTY then
  87.         set videoloc to videopath & video
  88.         put videoloc
  89.         importFileInto(member movieptr, videoloc)
  90.         set movieptr to movieptr + 1
  91.         next repeat
  92.       end if
  93.       set movieloc to EMPTY
  94.     end if
  95.   end repeat
  96.   saveMovie()
  97. end
  98.  
  99. on getrecords me, category, section
  100.   set reclist to 0
  101.   if stringp(section) then
  102.     set section to symbol(section)
  103.   end if
  104.   set categorytree to getaProp(sectiontree, section)
  105.   if listp(categorytree) then
  106.     if stringp(category) then
  107.       set category to symbol(category)
  108.     end if
  109.     if category = #all then
  110.       set reclist to []
  111.       repeat with catlist in categorytree
  112.         repeat with rec in catlist
  113.           append(reclist, rec)
  114.         end repeat
  115.       end repeat
  116.     else
  117.       set reclist to getaProp(categorytree, category)
  118.       if not listp(reclist) then
  119.         put "Bad category:" && category
  120.       end if
  121.     end if
  122.   else
  123.     put "Bad section:" && section
  124.   end if
  125.   return reclist
  126. end
  127.  
  128. on dispose me
  129. end
  130.